<template>
  <div style="display: inline-block;">
    <el-dialog :visible.sync="dialog" :close-on-click-modal="false" :before-close="cancel" append-to-body :fullscreen="dialog" @close="cancel">
      <div class="app-container">
        <!--表单组件-->
        <el-dialog v-if="crud.status.cu > 0" append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
          <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
            <el-form-item label="ADL项目名称" prop="bisAdlXmName">
              <el-input v-model="form.bisAdlXmName" style="width: 370px;" />
            </el-form-item>
            <el-form-item label="排序" prop="bisAdlXmPx">
              <el-input v-model="form.bisAdlXmPx" style="width: 370px;" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="text" @click="crud.cancelCU">取消</el-button>
            <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
          </div>
        </el-dialog>
        <!-- 字典列表 -->
        <el-row :gutter="10">
          <el-col :xs="24" :sm="24" :md="10" :lg="11" :xl="11" style="margin-bottom: 10px">
            <el-card class="box-card">
              <!--工具栏-->
              <div class="head-container">
                <div v-if="crud.props.searchToggle">
                  <!-- 搜索 -->
                  <el-input v-model="query.bisAdlXmName" clearable placeholder="ADL项目名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                  <rrOperation :crud="crud" />
                </div>
                <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
                <crudOperation :permission="permission" />
              </div>
              <!--表格渲染-->
              <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange">
                <el-table-column type="selection" width="55" />
                <el-table-column prop="bisAdlXmName" label="ADL项目名称" />
                <el-table-column prop="bisAdlXmPx" label="排序" />
                <el-table-column v-if="checkPer(['admin','adlXm:edit','adlXm:del'])" label="操作" width="150px" align="center">
                  <template slot-scope="scope">
                    <udOperation
                      :data="scope.row"
                      :permission="permission"
                    />
                  </template>
                </el-table-column>
              </el-table>
              <!--分页组件-->
              <pagination />
            </el-card>
          </el-col>
          <!-- 字典详情列表 -->
          <el-col :xs="24" :sm="24" :md="14" :lg="13" :xl="13">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>选项详情</span>
                <el-button
                  v-if="checkPer(['admin','adlPc:add']) && this.$refs.adlXmxx && this.$refs.adlXmxx.query.bisAdlXmName"
                  class="filter-item"
                  size="mini"
                  style="float: right;padding: 4px 10px"
                  type="primary"
                  icon="el-icon-plus"
                  @click="$refs.adlXmxx && $refs.adlXmxx.crud.toAdd()"
                >新增</el-button>
              </div>
              <adlXmxx ref="adlXmxx" :permission="permission" />
            </el-card>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import adlXmxx from './adlXmxx'
import crudAdlXm from '@/api/business/adlXm'
import CRUD, { presenter, header, form } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisAdlXmId: null, bisAdlXmName: null, bisAdlXmPx: null, adlXmxxes: [], ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, sfyx: null, bz: null }
export default {
  components: { pagination, crudOperation, rrOperation, udOperation, adlXmxx },
  mixins: [presenter(), header(),
    form(function() {
      return Object.assign({ adlPc: { bisAdlPcId: this.bisAdlPcId }}, defaultForm)
    })],
  cruds() {
    return CRUD({ title: 'ADL项目', url: 'api/adlXm', query: { bisAdlPcId: '' }, sort: 'bisAdlXmPx,desc', crudMethod: { ...crudAdlXm }})
  },
  data() {
    return {
      bisAdlPcId: null,
      dialog: false,
      permission: {
        add: ['admin', 'adlPc:add'],
        edit: ['admin', 'adlPc:edit'],
        del: ['admin', 'adlPc:del']
      },
      rules: {
        bisAdlXmName: [
          { required: true, message: 'ADL项目名称不能为空', trigger: 'blur' }
        ],
        bisAdlXmPx: [
          { required: true, message: '排序不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'bisAdlXmName', display_name: 'ADL项目名称' }
      ]
    }
  },
  created() {
    console.log('-----' + this.query.bisAdlPcId)
  },
  methods: {
    cancel() {
      this.dialog = false
      this.$refs.adlXmxx.queryFlag = false
      this.$refs.adlXmxx.query.bisAdlXmName = ''
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return this.dialog
    },
    // 选中字典后，设置字典详情数据
    handleCurrentChange(val) {
      if (val) {
        this.$refs.adlXmxx.queryFlag = val.true
        this.$refs.adlXmxx.bisAdlXmId = val.bisAdlXmId
        this.$refs.adlXmxx.query.bisAdlXmId = val.bisAdlXmId
        this.$refs.adlXmxx.query.bisAdlXmName = val.bisAdlXmName
        this.$refs.adlXmxx.crud.toQuery()
      }
    },
    // 编辑前临时清空，避免日志入库数据过长
    [CRUD.HOOK.beforeToEdit](crud, form) {
      // 避免日志入库数据过长
      form.adlXmxxes = null
    }
  }
}
</script>

<style scoped>

</style>
